package lihao3;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Test4 {
    public static void main(String[] args) {

        File mFile = new File("d:/");
        if (mFile.exists() && mFile.isDirectory()) {
            List<File> mlist = new ArrayList<File>();
            getAllFile(mFile, mlist);
            for (File file2 : mlist) {
                System.out.println(file2.getAbsolutePath());
            }
        }
    }

    private static void getAllFile(File mFile, List<File> mlist) {
        File[] files = mFile.listFiles();
        if (files != null) {

            for (File file : files) {
                if (file.isDirectory()) {
                    getAllFile(file, mlist);
                } else {
                    String fileName = file.getName();
                    if (fileName.endsWith(".jpg") || fileName.endsWith(".png")
                            || fileName.endsWith(".gif")) {
                        mlist.add(file);
                    }
                }
            }
        }
    }
}
